<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<HTML>
<HEAD>
<LINK REL=STYLESHEET TYPE="text/css" HREF="../../stylesheet.css" TITLE="Style">
<META NAME="GENERATOR" CONTENT="Java2HTML Version 1.5">
<TITLE>czestmyr.jjsched.Sender (Java2HTML)</TITLE>
</HEAD>
<BODY><TABLE id="Header" border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td colspan="2" width="33%">&nbsp;</td>
<td align="center" colspan="2" width="33%">
<font size="4">Sender.java</font>
</td>
<td align="right" colspan="2" width="33%">&nbsp;</td>
</tr>
</TABLE>
<pre ID="Classes">
<A NAME="1"></A><FONT ID="MultiLineComment">/*  This file is a part of JJSched source code
<A NAME="2"></A>    JJSched - Java Jabber Scheduler - a simple Jabber scheduling application
<A NAME="3"></A>    Copyright (C) 2008 Cestmir "CZestmyr" Houska
<A NAME="4"></A>
<A NAME="5"></A>    This program is free software: you can redistribute it and/or modify
<A NAME="6"></A>    it under the terms of the GNU General Public License as published by
<A NAME="7"></A>    the Free Software Foundation, either version 3 of the License, or
<A NAME="8"></A>    (at your option) any later version.
<A NAME="9"></A>
<A NAME="10"></A>    This program is distributed in the hope that it will be useful,
<A NAME="11"></A>    but WITHOUT ANY WARRANTY; without even the implied warranty of
<A NAME="12"></A>    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
<A NAME="13"></A>    GNU General Public License for more details.
<A NAME="14"></A>
<A NAME="15"></A>    You should have received a copy of the GNU General Public License
<A NAME="16"></A>    along with this program.  If not, see &lt;http://www.gnu.org/licenses/&gt; */</FONT>
<A NAME="17"></A>
<A NAME="18"></A><FONT ID="Package">package</FONT> czestmyr.jjsched;
<A NAME="19"></A>
<A NAME="20"></A><FONT ID="Import">import</FONT> java.sql.*;
<A NAME="21"></A>
<A NAME="22"></A><FONT ID="FormalComment">/**
<A NAME="23"></A> * Class that handles the periodic sending of planned events
<A NAME="24"></A> */</FONT>
<A NAME="25"></A><FONT ID="Public">public</FONT> <FONT ID="Class">class</FONT> Sender{
<A NAME="26"></A>    <FONT ID="Public">public</FONT> Sender(<A HREF="../../czestmyr/jjsched/DatabaseConnector.java.html">DatabaseConnector</A> newDbc, <A HREF="../../czestmyr/jjsched/Connector.java.html">Connector</A> newConn){
<A NAME="27"></A>        dbc = newDbc;
<A NAME="28"></A>        conn = newConn;
<A NAME="29"></A>    }
<A NAME="30"></A>
<A NAME="31"></A>    <FONT ID="FormalComment">/**
<A NAME="32"></A>     * Sends all actual messages to their subscribers.
<A NAME="33"></A>     *
<A NAME="34"></A>     * An actual message is a message that has an older timestamp than the current system time.
<A NAME="35"></A>     */</FONT>
<A NAME="36"></A>    <FONT ID="Public">public</FONT> <FONT ID="Void">void</FONT> sendActual(){
<A NAME="37"></A>        <FONT ID="Try">try</FONT> {
<A NAME="38"></A>            <FONT ID="Long">long</FONT> time = System.currentTimeMillis();
<A NAME="39"></A>
<A NAME="40"></A>            <FONT ID="SingleLineComment">//Select all actual user messages
<A NAME="41"></A></FONT>            ResultSet result = dbc.getUserEventsOlderThan(time);
<A NAME="42"></A>            <FONT ID="SingleLineComment">//For each message, check who it is for, and send it to the receiver
<A NAME="43"></A></FONT>            <FONT ID="While">while</FONT> (result.next()){
<A NAME="44"></A>                <FONT ID="SingleLineComment">//Get the needed data
<A NAME="45"></A></FONT>                String jid = result.getString(<FONT ID="StringLiteral">"jabber_id"</FONT>);
<A NAME="46"></A>                String description = result.getString(<FONT ID="StringLiteral">"description"</FONT>);
<A NAME="47"></A>                <FONT ID="SingleLineComment">//Send the message
<A NAME="48"></A></FONT>                conn.sendMessage(description, jid);
<A NAME="49"></A>            }
<A NAME="50"></A>
<A NAME="51"></A>            <FONT ID="SingleLineComment">//The first result set is not used anymore
<A NAME="52"></A></FONT>            dbc.dropResults();
<A NAME="53"></A>
<A NAME="54"></A>            <FONT ID="SingleLineComment">//Delete those messages from the DB
<A NAME="55"></A></FONT>            dbc.deleteUserEventsOlderThan(time);
<A NAME="56"></A>
<A NAME="57"></A>            <FONT ID="SingleLineComment">//Select all actual group messages
<A NAME="58"></A></FONT>            result = dbc.getGroupEventsOlderThan(time);
<A NAME="59"></A>            <FONT ID="SingleLineComment">//For each message, check who it is for, and send it to the receiver
<A NAME="60"></A></FONT>            <FONT ID="While">while</FONT> (result.next()){
<A NAME="61"></A>                <FONT ID="SingleLineComment">//Get the needed data
<A NAME="62"></A></FONT>                String jid = result.getString(<FONT ID="StringLiteral">"jabber_id"</FONT>);
<A NAME="63"></A>                String description = result.getString(<FONT ID="StringLiteral">"description"</FONT>);
<A NAME="64"></A>                <FONT ID="SingleLineComment">//Send the message
<A NAME="65"></A></FONT>                conn.sendMessage(description, jid);
<A NAME="66"></A>            }
<A NAME="67"></A>
<A NAME="68"></A>            <FONT ID="SingleLineComment">//The first result set is not used anymore
<A NAME="69"></A></FONT>            dbc.dropResults();
<A NAME="70"></A>
<A NAME="71"></A>            <FONT ID="SingleLineComment">//Delete those messages from the DB
<A NAME="72"></A></FONT>            dbc.deleteGroupEventsOlderThan(time);
<A NAME="73"></A>        } <FONT ID="Catch">catch</FONT> (Exception e) {
<A NAME="74"></A>            System.err.println(<FONT ID="StringLiteral">"sendActual() exception: "</FONT>+e.getMessage());
<A NAME="75"></A>        }
<A NAME="76"></A>    }
<A NAME="77"></A>
<A NAME="78"></A>    <FONT ID="Private">private</FONT> <A HREF="../../czestmyr/jjsched/DatabaseConnector.java.html">DatabaseConnector</A> dbc;
<A NAME="79"></A>    <FONT ID="Private">private</FONT> <A HREF="../../czestmyr/jjsched/Connector.java.html">Connector</A> conn;
<A NAME="80"></A>}
<A NAME="81"></A></pre>
</BODY>
</HTML>